#!/bin/bash

source ./config.sh

for index in $(seq 0 $((${#B_APPS[@]} - 1)))
do


  app_i=${B_APPS[$index]}
  app_i2=${app_i##*/}


  pass_t=${app_i2}_${B_ENERGYS[$index]}GeV_${B_SAMPLES[$index]}_${B_BFIELDS[$index]}Tesla_${B_PYLISTS[$index]}
  title_t=${pass_t}

  yaxis="Seconds"
     
  ### produce time summury file ###
  FN=`find ${OUTPUT_TIME_FILE_DIR} -name "${pass_t}_*.out"`
  echo -n "" > ${OUTPUT_TIME_FILE_DIR}/${pass_t}.sum

  for file in $FN
  do
    cat $file >> ${OUTPUT_TIME_FILE_DIR}/${pass_t}.sum
    echo "" >> ${OUTPUT_TIME_FILE_DIR}/${pass_t}.sum
  done

  ### draw histogram for the time summury file ###
  ${PWD}/drawHs ${OUTPUT_TIME_FILE_DIR}/${pass_t}.sum ${OUTPUT_TIME_FILE_DIR}/${pass_t}_TIME.gif ${title_t}__"("${yaxis}")"


  yaxis="Num_Of_Errors"
  ### draw histogram for the err summury file ###
  ${PWD}/drawHs ${OUTPUT_ERR_FILE_DIR}/${pass_t}.sum ${OUTPUT_ERR_FILE_DIR}/${pass_t}_ERR.gif ${title_t}__"("${yaxis}")"


  ### produce physics value summury file ###
  yaxis="PHY"
  case $app_i2 in
    ParN02 )
      yaxis="ParN02"
      ;;
    ParN03 )
      yaxis="Mean_Energy_in_Absorber"
      ;;
    SimplifiedCalo )
      yaxis="etotEM"
      ;;
  esac

  FN=`find ${OUTPUT_PHY_FILE_DIR} -name "${pass_t}_*.out"`
  echo -n "" > ${OUTPUT_PHY_FILE_DIR}/${pass_t}.sum

  for file in $FN
  do
    cat $file >> ${OUTPUT_PHY_FILE_DIR}/${pass_t}.sum
  done


  ### draw histogram for the physics summury file ###
  ${PWD}/drawHs ${OUTPUT_PHY_FILE_DIR}/${pass_t}.sum ${OUTPUT_PHY_FILE_DIR}/${pass_t}_PHY.gif  ${title_t}__"("${yaxis}")"


done


